package yxy.game.pm2.bean.db.newDao;

import yxy.apple.db.DbManager;
import yxy.game.pm2.bean.db.po.AchievementPo;

import java.util.ArrayList;
import java.util.List;

/**
 * @author James
 * @date 2022/1/22 13:49
 **/
public class AchievementDAO {
    private static final String
            REPLACE_ONE = "replace into `achievement` (`pCode`, `group`, `taskCodes`) values (?,?,?)",
            SELECT_ALL = "select * from `achievement` where `pCode` = ?";

    public static List<AchievementPo> getList(String playerCode) {
        return DbManager.instance().executeQueryObjectList(SELECT_ALL, new Object[]{playerCode}, AchievementPo.builder);
    }

    public static boolean replace(List<AchievementPo> achievements) {
        List<Object[]> list = new ArrayList<>();
        for (AchievementPo achievement : achievements) {
            Object[] objects = new Object[]{achievement.getPlayerCode(),achievement.getGroup(),achievement.getTaskCodes()};
            list.add(objects);
        }
        int[] ints = DbManager.instance().executeBatchCommand(REPLACE_ONE, list);
        return ints.length == achievements.size();
    }
}
